package greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 406. 根据身高重建队列
 * User: Li_yizYa
 * Date: 2025/6/26
 * Time: 17:50
 */
public class Solution11 {
    public int[][] reconstructQueue(int[][] people) {
        if (people == null || people.length == 0) {
            return new int[0][0];
        }
        Arrays.sort(people, (a, b) -> {
            if (a[0] != b[0]) {
                return b[0] - a[0];
            }
            return a[1] - b[1];
        });
        List<int[]> tmp = new ArrayList<>();
        for (int[] p : people) {
            tmp.add(p[1], p);
        }
        return tmp.toArray(new int[people.length][]);
    }
}
